package org.community.loginsvc.service.detailservice.userinfo;

import entity.CommonResult;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.community.loginsvc.service.detailservice.DetailService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Map;

@Service
@Transactional(
        isolation = Isolation.REPEATABLE_READ
)
@Slf4j
@Data
public class UserInfoService {

    @Resource
    private DetailService detailService;

    @Resource
    private UploadUserInfoToRedisService userInfoToRedisService;


    //获取用户信息并将用户信息上传至redis
    public void setUserInfo(Integer userInfo) throws IOException {
        log.info("setUserInfo开始执行");
        //获取用户文字信息
        CommonResult<Map<String,Object>> response = this.getDetailService().getUserInfo(userInfo,0);
        Map<String,Object> userInfoMap = response.getData();
//        log.info("用户信息：{}",userInfoMap);
        //存到认证库
        this.getUserInfoToRedisService().uploadToRedisByMap(userInfoMap,userInfo);
        //存到业务缓存库
        this.getUserInfoToRedisService().uploadToServiceRedis(userInfoMap,userInfo);
    }
}
